package com.spider.task;

import com.spider.dao.SpiderDao;
import com.spider.domain.Spider;
import com.spider.service.SpiderServiceI;
import com.spider.util.SpringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;
import java.util.Map;

public class SpiderManTask implements BaseTask {

    @Override
    public void execute(JobExecutionContext jobExecutionContext)
            throws JobExecutionException {
        //job+id
        String jobName = jobExecutionContext.getJobDetail().getKey().getName();
        String idStr = jobName.replace("spiderJob","");
        int id = idStr!=""?Integer.parseInt(idStr):0;
        SpiderServiceI ssi = (SpiderServiceI)SpringUtils.getBean("spiderServiceI");
        Spider s = ssi.getById(id);
        //System.out.println(s);
        Map<String, List<String>> map =  ssi.test(s);
        //判断是否选择了保存到数据库
        Map<String,Object> cmap = ssi.getColumnMap(s);
        if(cmap.size()>0){
            boolean b = ssi.saveData(cmap,map);
        }
    }
}
